package cn.joker;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@SpringBootApplication

public class PermissionsApp {
    public static void main(String[] args) {
        SpringApplication.run(PermissionsApp.class, args);
        System.out.println("权限系统启动成功！！");
    }
    @Bean
    public FilterRegistrationBean corsFilter() {

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        //表示是否允许客户端获取用户凭据。（布尔类型）
        config.setAllowCredentials(true);
        //config.addAllowedOrigin("http://localhost:9000");
        //表示允许哪些原始域进行跨域访问。（字符数组）
        config.addAllowedOrigin("*");
        //表示跨域请求的请求头信息。
        config.addAllowedHeader("*");
        //表示跨域请求的方式。（如GET/POST）
        config.addAllowedMethod("*");
        source.registerCorsConfiguration("/**", config); // CORS 配置对所有接口都有效
        FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
        bean.setOrder(0);
        return bean;
    }
}
